<template>
<!--  有且只有一个根节点-->
<!--  <div class="home">-->
<!--    <img alt="Vue logo" src="../assets/logo.png">-->
<!--    <HelloWorld msg="Welcome to Your Vue.js App"/>-->
<!--  </div>-->

  <div>
    <el-container>
<!--      100vh就是让左侧边栏占用整个浏览器100%的高度-->
      <el-aside :width="asideWidth" style="min-height: 100vh; background-color: #001529;">
<!--      <el-aside style="width: 200px; min-height: 100vh; background-color: #001529;">-->
        <div style="height: 60px;line-height: 60px; display: flex; align-items: center; justify-content: center">
          <img src="@/assets/sangulogo.png" alt="" style="width: 72px; height: 50px">
          <span style="margin-left: 5px; font-size: 20px; color: white" v-show="!isCollapse">三谷工具库</span>
        </div>

<!--    关闭动画:collapse-transition="false"-->
        <el-menu :collapse="isCollapse" :collapse-transition="false" router background-color="#001529" text-color="rgba(255,255,255,0.65)" active-text-color="#fff" style="border: none;" :default-active="$route.path">
<!--          只有一级菜单index属性才会生效高亮-->
          <el-menu-item index="/">
            <i class="el-icon-house"></i>
            <span slot="title">一级菜单1</span>
          </el-menu-item>
          <el-menu-item index="/ele">
            <i class="el-icon-aim"></i>
            <span slot="title">一级菜单2</span>
          </el-menu-item>
          <el-menu-item>
            <i class="el-icon-house"></i>
            <span slot="title">一级菜单3</span>
          </el-menu-item>
          <el-submenu index="">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>一级菜单4</span>
            </template>
            <el-menu-item>二级菜单1</el-menu-item>
            <el-menu-item>二级菜单2</el-menu-item>
            <el-menu-item>二级菜单3</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
<!--     头部区域-->
        <el-header>
<!--      展开/收缩 按钮-->
          <i :class="collapseIcon" style="font-size: 26px" @click="handleCollapse"></i>
<!--          <i class="el-icon-menu" style="width: 50px;"></i>-->
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px">
            <el-breadcrumb-item :to="{path: '/'}">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{path: '/ele'}">用户管理</el-breadcrumb-item>
          </el-breadcrumb>
          
          <div style="flex: 1;width: 0;display: flex;align-items: center;justify-content: flex-end">
            <i class="el-icon-full-screen" style="font-size: 26px" @click="handleFull"></i>
            <el-dropdown placement="bottom">
              <div style="display: flex; align-items: center; cursor: default">
                <img src="@/assets/userhead.jpg" alt="" style="width: 40px; height: 40px">
                <span>管理员</span>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item><div>个人信息</div></el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
<!--                <el-dropdown-item @click.native="$router.push('/login')">退出登录</el-dropdown-item>-->
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>            
          </div>
          
        </el-header>

        <el-main>
          <div style="box-shadow: 0 0 10px rgba(0,0,0,.1); padding:10px 20px;border-radius: 5px;margin-bottom: 10px">
            页面内容正在开发中……
          </div>
          <div style="display: flex">
            <el-card style="width: 30%">
              <div slot="header" class="clearfix">
                <span>正在开发中</span>
              </div>
              <div>
                有问题联系管理员QQ:55108001
                <div style="margin: 10px 0">
                  <strong>选择主题色</strong>
                </div>
                <el-button type="primary">选择此主题</el-button>
                <el-button type="success">选择此主题</el-button>
                <el-button type="warning">选择此主题</el-button>
                <el-button type="danger">选择此主题</el-button>
                <el-button type="info">选择此主题</el-button>
              </div>
            </el-card>

            <el-card style="width: 70%; margin-left: 10px">
              <div slot="header" class="clearfix">
                <span>所有用户数据</span>
              </div>
              <div>
                <el-table :data="users">
                  <el-table-column label="ID" prop="id"></el-table-column>
                  <el-table-column label="账号" prop="username"></el-table-column>
                  <el-table-column label="姓名" prop="name"></el-table-column>
                  <el-table-column label="手机" prop="phone"></el-table-column>
                  <el-table-column label="邮箱" prop="email"></el-table-column>
                  <el-table-column label="地址" prop="address"></el-table-column>
                  <el-table-column label="文件上传">
                    <template v-slot="scope">
                      <el-upload
                          action="http://192.168.31.121:8080/file/upload"
                          :headers="{token: user.token}"
                          :show-file-list="false"
                          :on-success="(row,file,fileList) => handleTableFileUpload(scope.row,file,fileList)"
                      >
                        <el-button size="mini" type="primary">点击上传</el-button>
<!--                        <div slot="tip" class="el-upload__tip">注意上传文件大小不要超过10MB，特殊格式可联系管理员修改系统</div>-->
                      </el-upload>

                    </template>
                  </el-table-column>

                  <el-table-column label="文件预览">
                    <template v-slot="scope">
                      <el-image v-if="scope.row.avatar" :src="scope.row.avatar" style="width: 50px;height: 50px"></el-image>
                      <div>
                        <el-button @click="preview(scope.row.avatar)">预览</el-button>
                      </div>
                    </template>
                  </el-table-column>

                  <el-table-column label="文件下载">
                    <div style="margin: 10px 0">
                      <el-input v-model="url"></el-input>
                      <el-button type="primary">下载文件</el-button>
                    </div>
                  </el-table-column>
                </el-table>
              </div>
            </el-card>
          </div>

          <div style="display: flex;margin: 10px 0">
            <el-card style="width: 50%;">
              <div slot="header" class="clearfix">
                <span>文件上传和下载</span>
              </div>

              <div>
                <el-upload
                    action="http://192.168.31.121:8080/file/upload"
                    list-type="picture"
                    :headers="{token: user.token}"
                    :on-success="handleFileUpload">
                  <el-button size="small" type="primary">单文件上传</el-button>
                </el-upload>
              </div>

              <div style="margin: 10px 0">
                <el-upload action="http://192.168.31.121:8080/file/upload" :headers="{token: user.token}" :on-success="handleMultipleFileUpload" multiple>
                  <el-button size="small" type="success">多文件上传</el-button>
                </el-upload>
              </div>

            </el-card>

          </div>

        </el-main>
      </el-container>
    </el-container>

  </div>

</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'

// export default {
//   name: 'HomeView',
//   components: {
//     HelloWorld
//   }
// }

// import axios from "axios";
import request from "@/utils/request";

export default {
  name: 'HomeView',
  data() {
    return {
      isCollapse: false, //左侧边栏默认不收缩
      asideWidth: '200px',
      collapseIcon: 'el-icon-s-fold',
      users: [],
      user: JSON.parse(localStorage.getItem('userInfo') || '{}'),
      url: ''
    }
  },
  //请求数据
  mounted() {
    // axios.get('http://localhost/user/findAll')
    // .then(res => { //页面加载后
    //   // console.log(res.data.data);
    //   this.users = res.data.data;
    // })
    request.get('/user/findAll').then(res => {
      this.users = res.data;
    })

  },

  methods: {
    preview(url){
      window.open(url)
    },
    //多文件上传
    handleMultipleFileUpload(res,file,fileList){
      //fileList是多文件的重点

    },
    //表格单文件上传处理器
    handleTableFileUpload(row,file,fileList){
      row.avatar = file.response.data //柔和赋值
      // this.$set(row,'avatar',file.response.data) //强硬赋值
      //触发更新数据库
      request.put('/user/update',row).then(res => {
        if (res.code == '200'){
          this.$message.success("上传成功")
        }else {
          this.$message.error("上传失败："+res.msg)
        }
      })
    },

    //文件上传成功之后的钩子
    handleFileUpload(res,file,fileList){
      console.log(res);
      console.log(file);
      console.log(fileList);
      this.fileList = fileList;
    },
    logout(){
      localStorage.removeItem("userInfo")
      this.$router.push('/login')
    },
    handleCollapse(){
      this.isCollapse = !this.isCollapse;
      this.asideWidth = this.isCollapse ? '64px' : '200px';
      this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
    },
    handleFull(){
      document.documentElement.requestFullscreen();
    }
  }
}

</script>

<style>
/*二级菜单 强制改黑色*/
.el-menu--inline .el-menu-item{
  background-color: #000c17 !important;
  /*纠正字体向左偏移(包括图标的24px和图标5px边距)*/
  padding-left: 49px!important;
}

/*鼠标聚焦高亮 这里是渐变色 i是非渐变色*/
.el-menu-item:hover, .el-submenu__title:hover, .el-submenu__title:hover i{
  color: #fff !important;
}

/*菜单背景色*/
.el-menu-item.is-active {
  /*上下左右腾出空间，防止间隙过窄*/
  /*margin: 4px;*/
  background-color: #1890ff!important;
  border-radius: 15px;
  width: calc(100% - 8px);
  margin-left: 4px;
}

/*图标偏右改为居中：设置高亮的margin left    展开时是i   收缩时是el-tooltip */
.el-menu-item.is-active i, .el-menu-item.is-active el-tooltip {
  margin-left: -4px;
}

/*一级菜单 和 二级菜单 限制高度*/
.el-menu-item,.el-submenu__title{
  height: 40px!important;
  line-height: 40px!important;
}

.el-header {
  box-shadow: 2px 0 6px rgba(8,21,41,.35);
  display: flex;
  align-items: center;
}


</style>
